package com.hanamaki.day1.day3;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.io.File;

public class Demo2 {
    //注册驱动
    WebDriver driver;
    WebDriver.Navigation navigation;
    @BeforeMethod
    public void setUp(){
        System.setProperty("webdriver.gecko.driver", "C:\\Program Files\\Mozilla Firefox\\geckodriver.exe");
        driver = new FirefoxDriver();
        navigation = driver.navigate();

    }
    @Test
    public void test(){
        driver.get("file:///C:/Users/Administrator/Desktop/testhtml/exam/House.html");
        WebElement fileUpload = driver.findElement(By.xpath("//input[@type='file']"));
        /*文件路径*/
        String filePath = "D:\\javaSpace\\ideaSpace\\JavaPageSources\\selenium-maven-study\\src\\main\\java\\com\\hanamaki\\study\\day02\\SeleniumTemplate1.java";
        /*IO流 File*/
        File file = new File(filePath);
        boolean exists = file.exists();
        if (exists){
            file.canExecute();
            fileUpload.sendKeys(filePath);
        }
        File screenshotAs = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);



    }
    @AfterMethod
    public void close(){

    }
}
